package com.demo.springbooot_demo.exception;

import com.demo.springbooot_demo.pojo.ResponseMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestControllerAdvice //统一处理
public class GlobalExceptionHandlerAdvice {
    Logger log= LoggerFactory.getLogger(GlobalExceptionHandlerAdvice.class);
    @ExceptionHandler(Exception.class)
    public ResponseMessage handlerException(Exception e, HttpServletRequest request, HttpServletResponse response){
        //记录日志
        log.error("统一异常",e);
        return  new ResponseMessage(500,"error",null);
    }
}
